#ifndef __SERVERPROTOCOL_H__
#define __SERVERPROTOCOL_H__

#include <QObject>
#include <QList>
#include <QString>

#include "faketcp.h"
#include "serverprotocolaction.h"
#include "common/status.h"
#include "common/chat.h"

class ServerProtocol: public QObject {

Q_OBJECT

public:
	ServerProtocol(FakeTcp* socket);
	~ServerProtocol();
	
	bool hasReadyActions();
	ServerProtocolAction* getAction();
signals:
	void readyAction();
private slots:
	void readMessage();
private:
	void parseConnection(QString message, QString ip, quint16 port);
	void parseChat(QString message, QString ip, quint16 port);
	void parseUser(QString message, QString ip, quint16 port);
	void parseFriend(QString message, QString ip, quint16 port);

	FakeTcp* socket;
	QList<ServerProtocolAction*> actions;
};

class ServerConnectionProtocol {
public:
	static void sendKeepAlive(FakeTcp* socket);
	static void deny(FakeTcp* socket);
	static void accept(FakeTcp* socket, Friend* f);
};

class ServerChatProtocol {
public:
	static void start(FakeTcp* socket, Chat* chat);
	static void send(FakeTcp* socket, Chat* chat, Friend*, QString message);
	static void exit(FakeTcp* socket, Chat* chat, Friend* f);
	static void enter(FakeTcp* socket, Chat* chat, Friend* f);
	static void terminate(FakeTcp* socket, Chat* chat);
};

class ServerUserProtocol {
public:
	static void friendStatus(FakeTcp* socket, Friend* f);
	static void friendList(FakeTcp* socket, QList<Friend*> friends);
	static void changePassword(FakeTcp* socket, bool isPasswordOk);
};

class ServerFriendProtocol {
public:
	static void invite(FakeTcp* socket, QString login);
	static void deny(FakeTcp* socket, QString login);
	static void add(FakeTcp* socket, Friend* f);
	static void remove(FakeTcp* socket, Friend* f);
};

#endif
